package com.yanqu.road.server.cmd.player;

import com.yanqu.road.pb.recharge.RechargeProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.logic.platform.DeductIngotsManager;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Cmd(code = Protocol.S_DEDUCT_INGOTS, desc = "扣除元宝")
public class DeductIngotsCmd extends AbstractCommand {

    private static Logger logger = LogManager.getLogger(DeductIngotsCmd.class.getName());
    private String orderNo;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        RechargeProto.DeductIngotsMsg reqMsg = RechargeProto.DeductIngotsMsg.parseFrom(packet.getBytes());
        orderNo = reqMsg.getOrderNo();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
         GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(player.getUserId());
         if(null != onlinePlayer){
             DeductIngotsManager.notifyPlayerDeductIngots(orderNo);
         }else{
             logger.warn("订单扣除元宝玩家不在线{}", orderNo);
         }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
